#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def validate_uci_file(file_path):
    """验证UCI配置文件"""
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
        
        lines = content.splitlines()
        config_count = content.count("config ")
        option_count = content.count("option ")
        
        print(f"文件: {file_path}")
        print(f"总行数: {len(lines)}")
        print(f"总字符数: {len(content)}")
        print(f"config块数量: {config_count}")
        print(f"option行数量: {option_count}")
        
        # 检查格式
        print("\n格式验证:")
        for i, line in enumerate(lines[:50], 1):  # 只检查前50行
            if line.strip() and not line.startswith('#'):
                if line.startswith("config "):
                    print(f"✓ 第{i}行: 配置块开始 - {line.strip()}")
                elif line.startswith("\toption "):
                    print(f"✓ 第{i}行: 选项设置 - {line.strip()}")
                elif line.strip() == "":
                    continue
                else:
                    print(f"? 第{i}行: {line.strip()}")
        
        print(f"\n✅ UCI配置文件验证完成！")
        print(f"成功转换了 {config_count} 个APN配置")
        
    except Exception as e:
        print(f"验证失败: {e}")

if __name__ == "__main__":
    validate_uci_file("apn_config.uci")